<template>
	<view class="mask">
		<u-popup v-model="activaModalshow" mode="false" closeOnClickOverlay="false">
			<view class="content" :class="[lang !== 'cn' ? 'heigt-over' :'']">
				<image class="content-imgbg"
					src="https://tongyongjiakao-1307163845.cos.ap-shanghai.myqcloud.com/used_img/activebg.png"></image>
				<view class="content-box">
					<view class="title">
						{{ $t('activateion.activatesoft') }}
					</view>
					<view class="usernum">
						<view class="">{{ $t('activateion.usernum') }}</view>
						<input type="number" class="usernum-input" @input="onkahao" :value="kahaonum" />
					</view>
					<view class="usernum">
						<view class="">{{ $t('activateion.password') }}</view>
						<input type="number" password="true" class="usernum-input" @input="onkami" :value="kaminum" />
					</view>
					<view class="active" @click="onaction(0)">
						{{ $t('activateion.action') }}
					</view>
					<view class="tiaoli">
						<label @click="setDoamin">
							<checkbox :checked="racheck" class="mycheck" style="transform:scale(0.7)" />
							<text>{{ $t('activateion.agree') }}</text>
						</label>
					</view>
					<view class="box_1 flex-row justify-between">
						<view class="image_2"></view>
						<text class="text_5">{{ $t('activateion.其他功能') }}</text>
						<view class="image_3"></view>
					</view>
					<view class="shiyong-jihuo">
						<view class="shiyong btn" @click="link('ontrial')">
							{{ $t('activateion.ontrial') }}
						</view>
						<view class="jihuo btn" @click="link('buycode')">
							{{ $t('activateion.buycode') }}
						</view>
					</view>
					<!-- <view class="tuixiaoyuan" @click="kefulink">
					{{ $t('activateion.agent') }}
				</view> -->
					<view class="tuixiaoyuan" @click="link('/ucenter/shopcart')">
						{{ $t('activateion.agent') }}
					</view>
				</view>
			</view>
		</u-popup>
		<u-popup ref="popup1" class="popup" v-model="wxloginshow" :round="30" mode="bottom" @close="close" @open="open">
			<view class="loginBox">
				<view class="btnBox">
					<view class="loginbtnk">
						<button class="weichat" open-type="getUserInfo" @click="wxlogin()">
							<u-icon name="weixin-fill" color="#ffffff"></u-icon>
							<text>微信登陆</text>
						</button>
					</view>
					<view class="loginbtnk-apple" v-if="loginshenhe" @click="applogin()">
						<image class="apple-img" src="/static/appleid_button.png"></image>
					</view>
					<!-- #ifdef APP-PLUS -->
					<!-- #endif -->
				</view>


				<view class="redtext" @click="openweb">
					{{ $t('activateion.regulations') }}
				</view>
				<view class="login-check" @click="setDoamin">
					<label>
						<checkbox :checked="racheck" style="transform:scale(0.7)" />
						{{ $t('activateion.agree') }}
					</label>
				</view>
			</view>

		</u-popup>
	</view>
</template>

<script>
	import {
		siteurl,
		wxlogin_api,
		jihuo_api, //地址添加修改接口
		updpk_api, //版本信息
		wxminilogin_api
	} from '@/api/index';


	export default {
		props: ['wxflag'],
		data() {
			return {
				lang: this.$i18n.locale,
				kahaonum: '', //卡号
				kaminum: '', //卡密
				isConnected: true, //判断网络状态
				wxloginshow: true,
				shenhe: false, //审核状态
				cartype: 'jiashizheng',
				tmpimg: '',
				anleanniu: true,
				loginshenhe: true,
				racheck: false, //选择用户协议， 如果没有勾选false
				jshenhe: false,
				kftel: '15688353919',
				activaModalshow: true


			}
		},
		onShow: function() {
			console.log("home-监听页面显示");
			var that = this;

			// that.userstat();

			//执行频率：game（20ms/次）、ui（60ms/次）、normal（200ms/次）
			var ontrials = uni.getStorageSync('ontrial_time'); //tiyan_times
			console.log("ontrials", ontrials)

			var tiyan_times = uni.getStorageSync('tiyan_times'); //tiyan_times
			console.log("tiyan_times", tiyan_times)



		},

		created() {
			// this.wxloginshow = this.wxflag
			console.log('anning~~~~~~~~~~~~~~~~~~~~~~~~~~~~', this.wxflag);
			console.log("langlang", this.lang)
			var that = this
			//判断机型
			var typeterminals = that.$kterminal;
			console.log("typeterminals*****", typeterminals);

			if (typeterminals == 'android') {
				that.shenhe = true;
				that.loginshenhe = false;
			}
			if (typeterminals == 'ios') {
				that.loginshenhe = true;
			}

			const racheckvalue = uni.getStorageSync('racheck');
			if (racheckvalue) {
				that.racheck = true
			}
			//获取客服电话  jia
			that.tekserws();

			// #ifdef APP-PLUS
			that.banben()
			// #endif

			//页面不要满屏
			//判断网络状态
			uni.getNetworkType({
				success: res => {
					if (res.networkType == 'none') {
						this.isConnected = false;
					} else {
						this.isConnected = true;
					}
				}
			});

			uni.onNetworkStatusChange(res => {
				this.isConnected = res.isConnected;
			});
			//判断驾驶证或资格证有没有选择
			uni.getStorage({
				key: 'exam_type',
				success: function(res) {
					that.cartype = res.data;
					console.log('已经设置过了，不要重复设置，如果想重复设置，请清理kem——type');
				},
				fail(e) {
					console.log('没有设置科目，请继续设置');
					uni.navigateTo({
						url: '../setting/setting'
					});
				}
			});

			//判断登录状态、
			uni.getStorage({
				key: 'user_infos',
				success: function(res) {
					// console.log("wxwxwxwx",res)
					that.wxloginshow = false;
					//判断是否激活过 如果激活过，跳转到首页，如果没没有激活，继续激活
					// userstatus -- -3其他情况 -2到期 -1禁用 0-不是会员 1-普通会员 2-高级会员 3代理

					var userstatus = res.data.userstatus;
					console.log("eeeeeeeeeeeeeeeeeeeeeeeeeeeee", userstatus);
					if (userstatus == 'undefined') {
						console.log('re login');
						uni.removeStorage({
							key: 'user_infos',
							success: function(res) {
								uni.showModal({
									title: that.$t('jihuo.提示'),
									content: that.$t('jihuo.登录信息已超时'),
									success: function(res) {
										that.wxloginshow = true;
										if (res.confirm) {
											console.log('用户点击确定');
										} else if (res.cancel) {
											console.log('用户点击取消');
										}
									}
								});
							}
						});
						return false;
					}

					if (userstatus == -1) {
						//禁用状态
						uni.showModal({
							title: that.$t('jihuo.提示'),
							content: that.$t('jihuo.您的账号已禁用'),
							success: function(res) {
								if (res.confirm) {
									console.log('用户点击确定');
								} else if (res.cancel) {
									console.log('用户点击取消');
								}
							}
						});
						return false;
					}
					if (userstatus == -3) {
						//禁用状态
						uni.showModal({
							title: that.$t('jihuo.提示'),
							content: that.$t('jihuo.您的账号已出现问题'),
							success: function(res) {
								if (res.confirm) {
									console.log('用户点击确定');
								} else if (res.cancel) {
									console.log('用户点击取消');
								}
							}
						});
						return false;
					}
					if (userstatus == -2) {
						//禁用状态
						uni.showModal({
							title: that.$t('jihuo.提示'),
							content: that.$t('jihuo.您的账号已到期'),
							success: function(res) {
								if (res.confirm) {
									console.log('用户点击确定');
								} else if (res.cancel) {
									console.log('用户点击取消');
								}
							}
						});
						return false;
					}

					if (userstatus == 0) {
						return false;
					}
					if (userstatus > 0) {
						//判断时间是否到？
						let timestamp = new Date().getTime();
						let jieshuriqi = res.data.jieshuriqi;
						console.log("日期比较", timestamp, jieshuriqi)
						if (jieshuriqi < timestamp) {
							//时间到期
							if (that.isConnected == false) {
								uni.showModal({
									title: that.$t('jihuo.提示'),
									content: that.$t('jihuo.请联网后重新激活'),
									success: function(res) {
										if (res.confirm) {
											console.log('用户点击确定');
										} else if (res.cancel) {
											console.log('用户点击取消');
										}
									}
								});
							} else {
								uni.showModal({
									title: that.$t('jihuo.提示'),
									content: that.$t('jihuo.您的账号已到期'),
									success: function(res) {
										//更改用户session信息
										const value = uni.getStorageSync('user_infos');
										var obj = JSON.parse(
											'{"openid":"' +
											value.openid +
											'","unionid": "' +
											value.unionid +
											'","kaishiriqi":"' +
											value.kaishiriqi +
											'","jieshuriqi":"' +
											value.jieshuriqi +
											'","userstatus":"' +
											-2 +
											'","jihuofangshi":"' +
											value.jihuofangshi +
											'","nick_name":"' +
											value.nick_name +
											'","pic_url":"' +
											value.pic_url +
											'","uid":"' +
											value.uid +
											'","dailijibie":"' +
											value.dailijibie +
											'"}'
										);

										if (res.confirm) {
											console.log('用户点击确定');
											uni.setStorage({
												key: 'user_infos',
												data: obj,
												success: function() {
													console.log('success');
													// uni.reLaunch({
													// 	url:"../index/start"
													// })
												}
											});
										} else if (res.cancel) {
											console.log('用户点击取消');
											uni.setStorage({
												key: 'user_infos',
												data: obj,
												success: function() {
													console.log('success');
													// uni.reLaunch({
													// 	url:"../index/start"
													// })
												}
											});
										}
									}
								});
							}
						} else {
							//直接跳转到首页
							that.tiaozhuan();
						}
					}

				},
				fail(err) {
					console.log("没有登陆", err)
					that.wxloginshow = true;
				}
			})




		},
		methods: {

			tekserws: function() {
				var that = this;
				//获取客服手机号接口
				that.http({
					url: "jia.json",
					method: 'GET',
					header: {
						// 'content-type': 'application/x-www-form-urlencoded'
						'content-type': 'application/json'
					},
					data: {},
					success: resmm => {
						console.log(resmm);
						// that.teks = resmm.tekserw;
						//that.jshenhe = resmm.fasker;

						var jvalue = resmm.fasker

						var typeterminals = that.$kterminal;
						console.log("typeterminals----=", typeterminals)
						if (typeterminals == 'android') {
							that.jshenhe = false;
							uni.setStorageSync('jshenhe', false);
						} else {
							that.jshenhe = jvalue;
							uni.setStorageSync('jshenhe', jvalue);
						}

						//that.jshenhe = true;
						that.kftel = resmm.kefu;



					},
					fail: err => {
						console.log(err);
					}

				});
			},
			//版本
			banben: function() {
				var that = this;
				console.log("进入版本信息了")
				that.https({
					url: updpk_api,
					method: 'POST',
					header: {
						'content-type': 'application/json'
					},
					data: {},
					success: res => {
						console.log(res);
						let versi = res.versionInfo.type;
						console.log('versi=', versi);
						var typeterminals = that.$kterminal;
						if (versi == 1) {
							if (typeterminals == 'android') {
								that.shenhe = true;

							} else {
								that.shenhe = false;
								that.loginshenhe = false
							}
							//that.shenhe = false;
						} else {
							that.loginshenhe = true;
							that.shenhe = true;
							//that.racheck = true;
						}
					},
					fail: err => {
						console.log(err);
					}
				});
			},
			/**
			 * 苹果用户登陆
			 * */
			// 苹果登录
			applogin: function() {
				var that = this;
				if (that.racheck === false) {
					uni.showModal({
						content: '请登陆前同意用户协议',
						showCancel: false
					});
					return false;
				} else {
					uni.showLoading({
						title: '加载中'
					});

					uni.login({
						provider: 'apple',
						success: function(loginRes) {
							console.log("loginRes", loginRes)
							// 登录成功
							uni.getUserInfo({
								provider: 'apple',
								success(oauth) {
									// 获取用户信息成功

									console.log('oauth info');
									console.log(oauth);
									console.log('oauth');
									console.log(oauth);
									var openid = '';
									var name = 'apple';
									var famila = '';
									var email = '';
									var formdata = oauth.userInfo;

									openid = formdata.openId;
									if (formdata.fullName.giveName) {
										name = formdata.fullName.giveName;
									}
									if (formdata.fullName.familyName) {
										famila = formdata.fullName.familyName;
									}

									if (formdata.email) {
										email = formdata.email;
									}
									var usrepic = siteurl + '/ios_logo.png';

									console.log(openid, name, famila, email);
									console.log('formdata');
									console.log(formdata);

									that.http({
										url: wxlogin_api,
										method: 'POST',
										header: {
											// 'content-type': 'application/x-www-form-urlencoded'
											'content-type': 'application/json'
										},
										data: {
											openid: openid,
											unionid: openid, //生成
											nick_name: name,
											pic_url: usrepic,
											sex: 1,
											gexing: null,
											devid: plus.device.uuid,

											system: 'stystemsios',
											system_info: 'system_infoios',
											version: '1.0.0',
											lang: that.lang,

											lastuptime: 0,
											apple_openid: openid,
											apple_name: name,
											apple_famila: famila,
											apple_email: email
											//苹果登录

											// unionid,
											// openid,
											// nick_name,	昵称
											// pic_url,
											// sex,		性别
											// gexing,		个性签名
											// devid,		硬件序列号
											// system,		设备类型:miniprog,android,iphone
											// system_info,	附加信息
											// version,	1.1.0	软件版本号
											// lastuptime,	上次题库更新时间戳
											// lang,		kz,ug,cn
											// apple_openid,
											// apple_name,
											// apple_famila,
											// apple_email
										},
										success: res => {
											console.log(res);
											console.log(JSON.stringify(res));
											//kaishiriqi --开始日期
											//jieshuriqi --结束日期
											// userstatus -- -3其他情况 -2到期 -1禁用 0-不是会员 1-普通会员 2-高级会员 3代理
											//存储openid
											uni.setStorageSync('openid', openid);

											var obj = JSON.parse(
												'{"openid":"' +
												openid +
												'","unionid": "' +
												openid +
												'","kaishiriqi":"' +
												res.kaishiriqi +
												'","jieshuriqi":"' +
												res.jieshuriqi +
												'","userstatus":"' +
												res.userstatus +
												'","jihuofangshi":"' +
												res.jihuofangshi +
												'","nick_name":"apple ","pic_url":"' +
												usrepic +
												'","uid":"' +
												res.uid +
												'","dailijibie":"' +
												res.dailijibie +
												'"}'
											);
											uni.setStorageSync('user_infos', obj);

											uni.showToast({
												title: '登陆成功',
												mask: false,
												duration: 1500
											});
											that.wxloginshow = false;
											//判断是否激活过 如果激活过，跳转到首页，如果没没有激活，继续激活
											// userstatus -- -3其他情况 -2到期 -1禁用 0-不是会员 1-普通会员 2-高级会员 3代理
											var userstatus = res.userstatus;
											//var userstatus = -2;
											if (userstatus == -1) {
												//禁用状态
												uni.showModal({
													title: that.$t('jihuo.提示'),
													content: that.$t(
														'jihuo.您的账号已禁用'),
													success: function(res) {
														if (res.confirm) {
															console.log(
																'用户点击确定'
															);
														} else if (res
															.cancel) {
															console.log(
																'用户点击取消'
															);
														}
													}
												});
												return false;
											}
											if (userstatus == -3) {
												//禁用状态
												uni.showModal({
													title: that.$t('jihuo.提示'),
													content: that.$t(
														'jihuo.您的账号已出现问题'),
													success: function(res) {
														if (res.confirm) {
															console.log(
																'用户点击确定'
															);
														} else if (res
															.cancel) {
															console.log(
																'用户点击取消'
															);
														}
													}
												});
												return false;
											}
											if (userstatus == -2) {
												//禁用状态
												uni.showModal({
													title: that.$t('jihuo.提示'),
													content: that.$t(
														'jihuo.您的账号已到期'),
													success: function(res) {
														if (res.confirm) {
															console.log(
																'用户点击确定'
															);
														} else if (res
															.cancel) {
															console.log(
																'用户点击取消'
															);
														}
													}
												});
												return false;
											}

											if (userstatus == 0) {

											}
											if (userstatus > 0) {
												//判断时间是否到？
												let timestamp = new Date().getTime();
												let jieshuriqi = res.jieshuriqi;
												if (jieshuriqi < timestamp) {
													//时间到期
													if (that.isConnected == false) {
														uni.showModal({
															title: that.$t(
																'jihuo.提示'
															),
															content: that.$t(
																'jihuo.请联网后重新激活'
															),
															success: function(
																res) {
																if (res
																	.confirm
																) {
																	console
																		.log(
																			'用户点击确定'
																		);
																} else if (
																	res
																	.cancel
																) {
																	console
																		.log(
																			'用户点击取消'
																		);
																}
															}
														});
													} else {
														uni.showModal({
															title: that.$t(
																'jihuo.提示'
															),
															content: that.$t(
																'jihuo.您的账号已到期'
															),
															success: function(
																res) {
																if (res
																	.confirm
																) {
																	console
																		.log(
																			'用户点击确定'
																		);
																} else if (
																	res
																	.cancel
																) {
																	console
																		.log(
																			'用户点击取消'
																		);
																}
															}
														});
													}
												} else {
													//直接跳转到首页
													that.tiaozhuan();
												}
											}

										},
										fail: err => {
											console.log(err);
										}
									});


								}
							});
						},
						fail: function(err) {
							console.log("e=", err)
							// 登录失败
							uni.showModal({
								content: '登录失败！请用微信一键登录方式登录',
								showCancel: false
							});
						},
						complete: function() {
							uni.hideLoading();
						}
					});
				}
				console.log('888');
				// 判断是 iOS13版本
			},
			//获取卡号
			onkahao(e) {
				this.kahaonum = e.target.value;
				// console.log("this.kahaonum", this.kahaonum)
			},
			//获取卡密
			onkami(e) {
				this.kaminum = e.target.value;
				// console.log("this.kahaonum", this.kahaonum)
			},

			open() {
				// console.log('open');
			},
			close() {
				this.wxloginshow = false
				// console.log('close');
			},
			//控制协议是否被选
			setDoamin: function() {
				var that = this;
				this.racheck = !this.racheck;
				console.log("chack ===" + that.racheck);

			},


			//隐私条例
			openweb: function() {
				console.log("11111")
				var that = this;
				uni.navigateTo({
					url: '../../template/index'
				});
				console.log("2222")
			},

			kefulink() {
				var that = this;
				uni.makePhoneCall({
					phoneNumber: that.kftel
				});
			},
			//微信登陆
			wxlogin: function() {
				var that = this;

				if (that.racheck === false) {
					uni.showModal({
						content: '请登陆前同意用户协议',
						showCancel: false
					});
					return false;
				} else {
					uni.setStorageSync('racheck', 'true')
					that.anleanniu = false;



					// #ifdef MP-WEIXIN
					var devid = '100010010';
					var system_info = 'miniprogram'

					stystems = 'miniprog';
					uni.login({
						provider: 'weixin',
						success: function(loginRes) {
							console.log("loginRes", loginRes);
							var code = loginRes.code;
							console.log("code", code);



							that.http({
								url: wxminilogin_api,
								method: 'POST',
								header: {
									// 'content-type': 'application/x-www-form-urlencoded'
									'content-type': 'application/json'
								},
								data: {
									jscode: code
								},
								success: res => {
									console.log("http", res);
									console.log(JSON.stringify(res));
									//login_result: "{"session_key":"d3UnTWLvO6Uq3sbbkU8oKw==","openid":"oZelb44C11VsTsrAW_kAhi5Qcwt4","unionid":"oYR7U5yjBVOTr-PI09kMQ0k6iwBs"}"
									//存储openid
									// 获取openid后开启
									//that.usersetinfo(res,openid,true);
									var ures = JSON.parse(res.login_result);
									console.log("ures=", ures);

									uni.getUserInfo({
										success: info => {
											console.log("getUserInfo", JSON
												.stringify(info));
											that.wxloginshow = false;

											var openids = ures.openid;
											var unionids = ures.unionid; //unionid
											// 与服务器交互将数据提交到服务端数据库
											that.http({
												url: wxlogin_api,
												method: 'POST',
												header: {
													// 'content-type': 'application/x-www-form-urlencoded'
													'content-type': 'application/json'
												},
												data: {
													openid: openids,
													unionid: unionids,
													nick_name: info
														.userInfo.nickName,
													pic_url: info.userInfo
														.avatarUrl,
													sex: info.userInfo
														.gender,
													gexing: null,
													devid: devid,
													system: stystems,
													system_info: system_info,
													version: '1.0.0',
													lastuptime: 0,
													lang: that.lang,

													apple_openid: null,
													apple_name: null,
													apple_famila: null,
													apple_email: null

												},
												success: resmm => {
													console.log(
														"resmm",
														resmm);
													console.log(JSON
														.stringify(
															resmm));
													that.usersetinfo(
														resmm,
														openids,
														info, true,
														unionids);
													//存储openid

												},
												fail: err => {
													console.log(err);
												}

											});
										},
										fail: () => {
											console.log('微信登录授权失败1');
											uni.showToast({
												title: '服务出现异常'
											});
										}
									});

								},
								fail: err => {
									console.log(err);

								}

							});
							//console.log(loginRes.authResult);
						},
						fail: ret => {
							console.log(ret);
							console.log('微信登录授权失败2');
							that.anleanniu = true;
							uni.showModal({
								content: '请登陆微信后再使用微信登陆',
								showCancel: false
							});

						},
						complete: () => {
							uni.hideLoading();
						}
					});
					// #endif



					var stystems = null;
					// #ifdef APP-PLUS
					// ifdef MP-WEIXIN
					uni.getSystemInfo({
						success: function(res) {
							if (res.platform == 'ios') {
								console.log('苹果机器');
								stystems = 'iphone';
							} else {
								console.log('不是苹果机器222');
								stystems = 'android';
							}
							console.log(res.platform);
						}
					});

					uni.login({
						provider: 'weixin',
						success: res => {
							console.log(JSON.stringify(res));
							// #ifdef APP-PLUS
							var devid = plus.device.uuid;
							var system_info = plus.device.model
							// #endif

							uni.getUserInfo({
								success: info => {
									console.log(JSON.stringify(info));
									that.wxloginshow = false;

									var openid = info.userInfo.openId;
									console.log("info.userInfo", info.userInfo);
									// 与服务器交互将数据提交到服务端数据库
									that.http({
										url: wxlogin_api,
										method: 'POST',
										header: {
											// 'content-type': 'application/x-www-form-urlencoded'
											'content-type': 'application/json'
										},
										data: {
											openid: openid,
											unionid: info.userInfo.unionId,
											nick_name: info.userInfo.nickName,
											pic_url: info.userInfo.avatarUrl,

											sex: info.userInfo.gender,
											gexing: null,
											devid: devid,

											system: stystems,

											system_info: system_info,
											version: '1.0.0',
											lastuptime: 0,
											lang: that.lang,

											apple_openid: null,
											apple_name: null,
											apple_famila: null,
											apple_email: null
											// console.log("Model: " + plus.device.model);
											// //获取设备的生产厂商
											// console.log("Vendor: " + plus.device.vendor);

											// unionid,
											// openid,
											// nick_name,	昵称
											// pic_url,
											// sex,		性别
											// gexing,		个性签名
											// devid,		硬件序列号
											// system,		设备类型:miniprog,android,iphone
											// system_info,	附加信息
											// version,	1.1.0	软件版本号
											// lastuptime,	上次题库更新时间戳
											// lang,		kz,ug,cn
											// apple_openid,
											// apple_name,
											// apple_famila,
											// apple_email
										},
										success: res => {
											console.log(res);
											console.log(JSON.stringify(res));
											that.usersetinfo(res, openid, info,
												true, info.userInfo.unionId);
											//存储openid

										},
										fail: err => {
											console.log(err);
											that.anleanniu = false;
										}

									});
								},
								fail: () => {
									console.log('微信登录授权失败1');
									that.anleanniu = false;
									uni.showToast({
										title: '服务器出现异常'
									});
								}
							});



						},
						fail: ret => {
							console.log(ret);
							console.log('微信登录授权失败2');
							that.anleanniu = true;
							uni.showModal({
								content: '请登陆微信后再使用微信登陆',
								showCancel: false
							});
						},
						complete: () => {
							uni.hideLoading();
						}
					});
					// #endif
				}
			},


			usersetinfo: function(res, openid, info, loginstatu, unionids) {
				var that = this;
				// console.log("res, openid, info, loginstatu, unionids", res, openid, info, loginstatu, unionids);
				uni.setStorageSync('openid', openid);
				if (loginstatu) {
					var obj = JSON.parse(
						'{"openid":"' +
						openid +
						'","unionid": "' +
						unionids +
						'","kaishiriqi":"' +
						res.kaishiriqi +
						'","jieshuriqi":"' +
						res.jieshuriqi +
						'","userstatus":"' +
						res.userstatus +
						'","jihuofangshi":"' +
						res.jihuofangshi +
						'","nick_name":"' +
						info.userInfo.nickName +
						'","pic_url":"' +
						info.userInfo.avatarUrl +
						'","uid":"' +
						res.uid +
						'","dailijibie":"' +
						res.dailijibie +
						'"}'
					);
				} else {
					var obj = JSON.parse(
						'{"openid":"' +
						openid +
						'","unionid": "' +
						info.unionid +
						'","kaishiriqi":"' +
						res.kaishiriqi +
						'","jieshuriqi":"' +
						res.jieshuriqi +
						'","userstatus":"' +
						res.userstatus +
						'","jihuofangshi":"' +
						res.jihuofangshi +
						'","nick_name":"' +
						info.nickname +
						'","pic_url":"' +
						info.avatarurl +
						'","uid":"' +
						res.uid +
						'","dailijibie":"' +
						res.dailijibie +
						'"}'
					);
				}
				console.log("obj", obj)
				uni.setStorageSync('user_infos', obj);
				if (loginstatu == true) {
					uni.showToast({
						title: '登陆成功',
						mask: false,
						duration: 1500
					});
				}

				that.anleanniu = true;
				that.wxloginshow = false;
				//判断是否激活过 如果激活过，跳转到首页，如果没没有激活，继续激活
				// userstatus -- -3其他情况 -2到期 -1禁用 0-不是会员 1-普通会员 2-高级会员 3代理
				var userstatus = res.userstatus;
				//修改状态码
				// var userstatus = -1;
				console.log("userstatus", userstatus)
				if (userstatus == -1) {
					//禁用状态
					uni.showModal({
						title: that.$t('jihuo.提示'),
						content: that.$t('jihuo.您的账号已禁用'),
						success: function(res) {
							if (res.confirm) {
								console.log('用户点击确定');
							} else if (res.cancel) {
								console.log('用户点击取消');
							}
						}
					});
					return false;
				}
				if (userstatus == -3) {
					//禁用状态
					uni.showModal({
						title: that.$t('jihuo.提示'),
						content: that.$t('jihuo.您的账号已出现问题'),
						success: function(res) {
							if (res.confirm) {
								console.log('用户点击确定');
							} else if (res.cancel) {
								console.log('用户点击取消');
							}
						}
					});
					return false;
				}
				if (userstatus == -2) {
					//禁用状态
					uni.showModal({
						title: that.$t('jihuo.提示'),
						content: that.$t('jihuo.您的账号已到期'),
						success: function(res) {
							if (res.confirm) {
								console.log('用户点击确定');
							} else if (res.cancel) {
								console.log('用户点击取消');
							}
						}
					});
					return false;
				}

				if (userstatus == 0) {
					//禁用状态

					return false;
				}
				if (userstatus > 0) {

					//判断时间是否到？
					let timestamp = new Date().getTime();
					let jieshuriqi = res.jieshuriqi;
					if (jieshuriqi < timestamp) {
						//that.tiaozhuan();
						//时间到期
						if (that.isConnected == false) {
							uni.showModal({
								title: that.$t('jihuo.提示'),
								content: that.$t('jihuo.请联网后重新激活'),
								success: function(res) {
									if (res.confirm) {
										console.log('用户点击确定');
									} else if (res.cancel) {
										console.log('用户点击取消');
									}
								}
							});
						} else {
							uni.showModal({
								title: that.$t('jihuo.提示'),
								content: that.$t('jihuo.您的账号已到期'),
								success: function(res) {
									if (res.confirm) {
										console.log('用户点击确定');
									} else if (res.cancel) {
										console.log('用户点击取消');
									}
								}
							});
						}
					} else {
						//直接跳转到首页
						// that.tiaozhuan();
						this.activaModalshow = false

					}
				}
			},

			//数据交互
			onaction(num) {
				var that = this;
				var type = num;
				if (that.racheck === false) {
					uni.showModal({
						content: '请同意用户协议后操作',
						showCancel: false
					});
					return false;
				} else {

					uni.getStorage({
						key: 'user_infos',
						success: function(res) {
							var stystems = null;
							// #ifdef APP-PLUS
							uni.getSystemInfo({
								success: function(res) {
									if (res.platform == 'ios') {
										console.log('苹果机器');
										stystems = 'iphone';
									} else {
										console.log('不是苹果机器222');
										stystems = 'android';
									}
									console.log(res.platform);
								}
							});
							// #endif

							// #ifdef MP-WEIXIN
							stystems = 'miniprog';
							// #endif
							console.log(res);
							var uinfo = res.data;

							if (that.kahaonum == '') {
								uni.showModal({
									title: that.$t('jihuo.提示'),
									content: that.$t('jihuo.卡号不能为空'),
									success: function(res) {
										if (res.confirm) {
											console.log('用户点击确定');
										} else if (res.cancel) {
											console.log('用户点击取消');
										}
									}
								});
								return false;
							}
							if (that.kaminum == '') {
								uni.showModal({
									title: that.$t('jihuo.提示'),
									content: that.$t('jihuo.卡密不能为空'),
									success: function(res) {
										if (res.confirm) {
											console.log('用户点击确定');
										} else if (res.cancel) {
											console.log('用户点击取消');
										}
									}
								});
								return false;
							}

							that.https({
								url: jihuo_api,
								method: 'POST',
								data: {
									kahao: that.kahaonum,
									kami: that.kaminum,
									type: type
								},
								success: res => {
									console.log(res);
									//console.log(res.data.result_code);
									console.log(res.result_code);

									//激活时:-1 用户没有登录，-2 用户已禁用，-3卡号或卡蜜错误，-4卡号没有销售，-5卡号已经激活不可重复使用，-6卡号被禁用，-7 其他错误,0 成功
									if (res.result_code == -1) {
										//用户没有登录,让他微信登录
										uni.showModal({
											title: that.$t('jihuo.提示'),
											content: that.$t('jihuo.用户没有登录'),
											success: function(resw) {
												if (res.confirm) {
													console.log('用户点击确定');
												} else if (res.cancel) {
													console.log('用户点击取消');
												}
											}
										});
										return false;
									}
									if (res.result_code == -2) {
										//用户已禁用
										uni.showModal({
											title: that.$t('jihuo.提示'),
											content: that.$t('jihuo.用户已禁用'),
											success: function(resw) {
												if (res.confirm) {
													console.log('用户点击确定');
												} else if (res.cancel) {
													console.log('用户点击取消');
												}
											}
										});
										return false;
									}
									if (res.result_code == -3) {
										//卡号或卡密错误
										uni.showModal({
											title: that.$t('jihuo.提示'),
											content: that.$t('jihuo.卡号或卡密错误'),
											success: function(resw) {
												if (res.confirm) {
													console.log('用户点击确定');
												} else if (res.cancel) {
													console.log('用户点击取消');
												}
											}
										});
										return false;
									}
									if (res.result_code == -4) {
										//-4卡号没有销售
										uni.showModal({
											title: that.$t('jihuo.提示'),
											content: that.$t('jihuo.卡号没有销售'),
											success: function(resw) {
												if (res.confirm) {
													console.log('用户点击确定');
												} else if (res.cancel) {
													console.log('用户点击取消');
												}
											}
										});
										return false;
									}
									if (res.result_code == -5) {
										//-5卡号已经激活不可重复使用
										uni.showModal({
											title: that.$t('jihuo.提示'),
											content: that.$t('jihuo.卡号已经激活不可重复使用'),
											success: function(resw) {
												if (res.confirm) {
													console.log('用户点击确定');
												} else if (res.cancel) {
													console.log('用户点击取消');
												}
											}
										});
										return false;
									}
									if (res.result_code == -6) {
										//-6卡号被禁用
										uni.showModal({
											title: that.$t('jihuo.提示'),
											content: that.$t('jihuo.卡号被禁用'),
											success: function(resw) {
												if (res.confirm) {
													console.log('用户点击确定');
												} else if (res.cancel) {
													console.log('用户点击取消');
												}
											}
										});
										return false;
									}
									if (res.result_code == -7) {
										//-7 其他错误
										uni.showModal({
											title: that.$t('jihuo.提示'),
											content: that.$t('jihuo.其他错误'),
											success: function(resw) {
												if (res.confirm) {
													console.log('用户点击确定');
												} else if (res.cancel) {
													console.log('用户点击取消');
												}
											}
										});
										return false;
									}
									if (res.result_code == -8) {
										//-7 其他错误
										uni.showModal({
											title: that.$t('jihuo.提示'),
											content: that.$t('jihuo.其他错误'),
											success: function(resw) {
												if (res.confirm) {
													console.log('用户点击确定');
												} else if (res.cancel) {
													console.log('用户点击取消');
												}
											}
										});
										return false;
									}
									if (res.result_code == 0) {
										//成功
										uni.showModal({
											title: that.$t('jihuo.提示'),
											content: that.$t('jihuo.激活成功'),
											success: function(resg) {
												//先获取用户信息
												const value = uni.getStorageSync(
													'user_infos');
												var obj = JSON.parse(
													'{"openid":"' +
													value.openid +
													'","unionid": "' +
													value.unionid +
													'","kaishiriqi":"' +
													res.kaishiriqi +
													'","jieshuriqi":"' +
													res.jieshuriqi +
													'","userstatus":"' +
													res.userstatus +
													'","jihuofangshi":"' +
													value.jihuofangshi +
													'","nick_name":"' +
													value.nick_name +
													'","pic_url":"' +
													value.pic_url +
													'","uid":"' +
													value.uid +
													'","dailijibie":"' +
													res.dailijibie +
													'"}'
												);

												try {
													uni.setStorageSync('user_infos',
														obj);
													uni.reLaunch({
														url: "../index/start"
													})
												} catch (e) {
													// error
												}

												// uni.setStorage({
												//     key: 'user_infos',
												//     data: obj,
												//     success: function () {
												//         console.log('success');

												//     }
												// });
												//uni.setStorageSync('user_infos', obj);
											}
										});
									}
									// {
									// 	"result_msg": "",
									// 	"jieshuriqi": "0",
									// 	"jiehuofangshi": "0",
									// 	"userstatus": "0",
									// 	"dailijibie": "0",
									// 	"result_code": "-1",
									// 	"kaishiriqi": "0"
									// }
									//this.addresslist = res;
								},
								fail: err => {
									console.log(err);
									uni.showModal({
										title: '错误',
										content: "服务器出现错误：" + err,
										success: function(resw) {
											if (res.confirm) {
												console.log('用户点击确定');
											} else if (res.cancel) {
												console.log('用户点击取消');
											}
										}
									});
								},
								complete: function(eeee) {
									//console.log(eeee,'com')
								}
							});

							console.log(that.kaminum, that.kahaonum);
						},
						fail() {
							//返回登录按钮，重新微信登录
							uni.hideLoading();
						}
					});
				}
			},

			// 跳转
			tiaozhuan: function(no) {
				var that = this;
				uni.getStorage({
					key: 'exam_type',
					success: function(res) {
						console.log('已经设置过了，不要重复设置，如果想重复设置，请清理kem——type');
						if (res.data == 'zigezheng') {
							console.log("zigezheng1111111111111111")
							if (no == true) {
								console.log("zigezheng11111111111112")
								uni.redirectTo({
									url: '../index/qualification?alert=1'
								});
							} else {
								console.log("zigezheng111111111111113")
								uni.redirectTo({
									url: '/pages/index/qualification?ontrial=true'
								})
							}

						} else {
							console.log("jiashizheng11111111111111111")
							if (no == true) {
								console.log("weeeeeeeeee")
								uni.redirectTo({
									url: '../index/index?alert=1'
								});
							} else {
								console.log("wwwwwwww")
								uni.redirectTo({
									url: '../../index/index'
								});
							}

						}
					},
					fail(e) {
						console.log('没有设置科目，请继续设置');
						uni.reLaunch({
							url: '../setting/setting'
						});
					}
				});
			},



			link: function(links) {
				var that = this;
				if (that.racheck === false) {
					uni.showModal({
						content: '请同意用户协议后操作',
						showCancel: false
					});
					return false;
				} else {
					if (links == 'ontrial') {
						if (that.cartype == 'jiashizheng') {
							uni.redirectTo({
								url: '/pages/index/index?ontrial=true'
							})
						} else {
							uni.redirectTo({
								url: '/pages/index/qualification?ontrial=true'
							})
						}
					} else if (links == 'buycode') {
						if (that.cartype == 'jiashizheng') {
							uni.redirectTo({
								url: '/pages/index/index?alert=1'
							})
						} else {
							uni.redirectTo({
								url: '/pages/index/qualification?alert=1'
							})
						}
					} else {
						uni.navigateTo({
							url: '/pages' + links
						})
					}
				}

			},
		}
	}
</script>

<style scoped lang="scss">
	.mask {
		width: 100%;
		height: 100%;
		// background-color: rgba(7, 7, 7, 0.28);

		.content {
			width: 590rpx;
			height: 910rpx;
			position: fixed;
			top: 216rpx;
			left: 80rpx;

			.content-imgbg {
				width: 100%;
				height: 100%;
				position: absolute;
				top: 0;
				left: 0;
			}

			.content-box {
				position: absolute;
				width: 590rpx;
				top: 93rpx;
				left: 13.5rpx;
				padding-left: 22rpx;
				padding-top: 91rpx;
				padding-bottom: 30rpx;
				box-sizing: border-box;
				width: 565rpx;
				// height: 795rpx;
				border-radius: 20rpx;
				border: 1rpx solid #E4BC8B;

				.title {
					font-size: 40rpx;
					font-family: PingFangSC-Medium, PingFang SC;
					font-weight: 500;
					color: #4C361B;
					line-height: 56rpx;
					margin-left: 138rpx;
				}

				.usernum {
					width: 516rpx;
					height: 79rpx;
					background: #FAE8D3;
					border-radius: 20rpx;
					line-height: 79rpx;
					padding-left: 34rpx;
					box-sizing: border-box;
					font-size: 30rpx;
					font-family: PingFangSC-Regular, PingFang SC;
					font-weight: 400;
					color: #744507;
					display: flex;
					margin-top: 36rpx;

					.usernum-input {
						margin-top: 15rpx;
					}
				}

				.active {
					width: 516rpx;
					height: 79rpx;
					border-radius: 50rpx;
					background: #E4BC8B;
					text-align: center;
					line-height: 79rpx;
					color: rgba(132, 95, 36, 1);
					font-size: 32rpx;
					font-family: PingFangSC-Medium;
					font-weight: 500;
					margin-top: 36rpx;
				}

				.tiaoli {
					margin-left: 84rpx;
					margin-top: 14rpx;
					font-size: 22rpx;
					font-family: PingFangSC-Regular, PingFang SC;
					font-weight: 400;
					color: #D9CBB3;
					line-height: 30rpx;
					// text-align: center;

				}

				.box_1 {
					width: 518rpx;
					margin-top: 20rpx;
					display: flex;

					.image_2 {
						width: 182rpx;
						height: 1rpx;
						margin: 15rpx 0 14rpx 0;
						background: #E4BC8B;
					}

					.text_5 {
						overflow-wrap: break-word;
						color: rgba(225, 191, 144, 1);
						font-size: 22rpx;
						font-weight: NaN;
						text-align: left;
						white-space: nowrap;
						line-height: 30rpx;
						margin: 0 20rpx;
					}

					.image_3 {
						width: 182rpx;
						height: 1rpx;
						margin: 15rpx 0 14rpx 0;
						background: #E4BC8B;
					}
				}

				.shiyong-jihuo {
					width: 517rpx;
					display: flex;
					justify-content: space-between;
					margin-top: 30rpx;

					.btn {
						border-radius: 8px;
						padding: 15rpx 55rpx 14rpx 55rpx;
						font-size: 28rpx;
						text-align: left;
						line-height: 40rpx;
					}

					.shiyong {
						background-color: rgba(225, 212, 190, 1);
						color: rgba(181, 166, 141, 1);
					}

					.jihuo {
						background-color: rgba(194, 56, 56, 1);
						color: rgba(255, 255, 255, 1);
					}
				}

				.tuixiaoyuan {
					background-color: rgba(13, 160, 255, 1);
					border-radius: 8px;
					margin-top: 20rpx;
					width: 516rpx;
					padding: 12rpx 182rpx 13rpx 182rpx;
					color: rgba(255, 255, 255, 1);
					font-size: 30rpx;
					text-align: center;
					line-height: 42rpx;
				}

			}


		}

		.heigt-over {
			height: 978rpx;
		}

		.popup {
			// height: 500rpx;

			.loginBox {
				width: 100%;
				height: 520rpx;
				padding: 120rpx 30rpx;
				box-sizing: border-box;

				.btnBox {
					width: 100%;
					height: 130rpx;

					.loginbtnk {
						width: 310rpx;
						margin: 10rpx;
						height: 120rpx;
						text-align: center;
						display: inline-block;
						float: left;
						margin-right: 40rpx;

					}

					.weichat {
						color: #ffffff;
						background: #0bd34e;
					}

					.loginbtnk-apple {
						color: #ffffff;
						width: 303rpx;
						height: 90rpx;
						// background-image: url('@/static/appleid_button.png');
						// background-size: 100% 100%;
						display: inline-block;
						margin-top: 12rpx;

						.apple-img {
							width: 100%;
							height: 100%;
						}

					}


				}

				.redtext {
					color: red;
					width: 100%;
					text-align: center;
					margin-top: 30rpx;
				}

				.login-check {
					width: 100%;
					text-align: center;
					margin-top: 40rpx;
				}


			}

		}

	}
</style>
